package logic

import (
	"context"
	"sport/sportrpc/sportrpc"

	"sport/api/internal/svc"
	"sport/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFindPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindPasswordLogic {
	return &FindPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FindPasswordLogic) FindPassword(req *types.FindPasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	password, err := l.svcCtx.Sportrpc.FindPassword(l.ctx, &sportrpc.FindPasswordRequest{
		Account:  req.Account,
		Password: req.Password,
		SendSms:  req.SendSms,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "找回密码成功",
		Data:    password,
		Code:    200,
	}, nil
}
